import os

os.makedirs('./image/', exist_ok=True)
IMAGE_URL = "https://ke-image.ljcdn.com/110000-inspection/6f935046-7127-4c50-b0e9-efbd035c59aa_1000.jpg!m_fill,w_280,h_210,f_jpg?from=ke.com"


def urllib_download():
    from urllib.request import urlretrieve
    urlretrieve(IMAGE_URL, './image/img1.png')


def request_download():
    import requests
    r = requests.get(IMAGE_URL)

    with open('./image/img2.png', 'wb') as f:
        f.write(r.content)


def chunk_download():
    import requests
    r = requests.get(IMAGE_URL, stream=True)
    with open('./image/img3.png', 'wb') as f:
        for chunk in r.iter_content(chunk_size=32):
            f.write(chunk)

if __name__ == '__main__':

    urllib_download()
    print('download img1')
    request_download()
    print('download img2')
    chunk_download()
    print('download img3')